import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:tvlives/provider/provider.dart';
import 'package:tvlives/route/Application.dart';
import 'package:tvlives/route/Routes.dart';
import 'package:tvlives/utils/Toast.dart';
import 'package:tvlives/values/theme_colors.dart';
import 'package:url_launcher/url_launcher.dart';

class MyPage extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
     return _MyState();
  }

}

class _MyState extends State<MyPage>{
  String _currentTheme;
  @override
  void initState() {
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    _currentTheme = Provider.of<ThemeInfo>(context).themeColor;
    return Scaffold(
      appBar: AppBar(
        title: Text("我",style: TextStyle(fontSize: 16.0),),
        centerTitle: true,
      ),
      body: buildColllumn(),
    );
  }

  Widget buildColllumn(){
       return Column(
         children: <Widget>[
           buildUser(),
           ListTile(
             leading: Icon(Icons.textsms),
             title: Text("消息中心"),
             trailing: Text("待开发",style: TextStyle(color: Colors.grey),),
             onTap: (){},
           ),
           ListTile(
             leading: Icon(Icons.visibility),
             title: Text("历史记录"),
             trailing: Text("待开发",style: TextStyle(color:Colors.grey),),
             onTap: (){},
           ),
           ListTile(
             leading: Icon(Icons.turned_in),
             title: Text("标签管理"),
             trailing: Text("待开发",style: TextStyle(color:Colors.grey),),
             onTap: (){},
           ),
           ListTile(
             leading: Icon(Icons.palette),
             title: Text("切换主题"),
             trailing: Icon(Icons.brightness_1,
             color:ThemeColors.themeColor[_currentTheme]["primaryColor"]),
             onTap: (){
               Application.router
                   .navigateTo(context, Routes.themeSetting, transition: TransitionType.inFromRight);
             },
           ),
           ListTile(
             leading: Icon(Icons.code),
             title: Text("关于项目"),
             trailing: Icon(Icons.navigate_next),
             onTap: (){
               showAboutDialog(
                 context: context,
                 applicationName: 'alltv',
                 applicationVersion: '1.2.0',
                 applicationIcon: Image.asset(
                   "assets/images/alltv.png",
                   width: 80,
                 ),
                 applicationLegalese: 'by HarryZhang',
                 children: <Widget>[
                   Text(
                     '本项目是业余时间所写，随缘更新维护。',
                     style: TextStyle(fontSize: 13.5),
                   ),
                   Text(
                     '如果你觉得有帮助到你,那就麻烦点个Star吧！',
                     style: TextStyle(fontSize: 13.5),
                   ),
                   ListTile(
                     contentPadding: EdgeInsets.only(left: 5),
                     leading: Image.asset(
                       "assets/images/Github.png",
                       width: 25,
                     ),
                     title: Text("Github"),
                     trailing: Icon(Icons.navigate_next),
                     onTap: () async {
                       await launch("https://github.com/ha2ryzhang/alltv_flutter");
                     },
                   ),
                   ListTile(
                     contentPadding: EdgeInsets.only(left: 5),
                     leading: Image.asset(
                       "assets/images/juejin.png",
                       width: 25,
                     ),
                     title: Text("HarryZhang的博客"),
                     trailing: Icon(Icons.navigate_next),
                     onTap: () async {
                       await launch(
                           "https://juejin.im/user/5ddb0cd4f265da7de03eca73");
                     },
                   ),
                 ],
               );
             },
           ),
         ],
       );
  }

  Widget buildUser(){
    return Container(
      margin: EdgeInsets.only(top: 10.0,bottom: 10.0),
      child: ListTile(
        onTap: (){
          showToast("努力开发中");
        },
        leading: CircleAvatar(
          radius: 25,
          backgroundColor: Colors.white,
          backgroundImage: Image.asset("assets/images/alltv.png").image,
        ),
        title: Text("alltv"),
        subtitle:Text("目前功能暂时比较少，请谅解"),
        trailing: Icon(Icons.navigate_next),
      ),

    );
  }
}